package cn.home.DYX.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.home.sysmanagement.domain.HomeTag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.home.common.annotation.Log;
import cn.home.common.core.controller.BaseController;
import cn.home.common.core.domain.AjaxResult;
import cn.home.common.enums.BusinessType;
import cn.home.DYX.domain.HomeDoctor;
import cn.home.DYX.service.IHomeDoctorService;
import cn.home.common.utils.poi.ExcelUtil;
import cn.home.common.core.page.TableDataInfo;

/**
 * 医生管理Controller
 * 
 * @author 丁宇翔
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/system/doctor")
public class HomeDoctorController extends BaseController
{
    @Autowired
    private IHomeDoctorService homeDoctorService;

    /**
     * 查询医生管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:doctor:list')")
    @GetMapping("/list")
    public TableDataInfo list(HomeDoctor homeDoctor)
    {
        startPage();
        List<HomeDoctor> list = homeDoctorService.selectHomeDoctorList(homeDoctor);
        return getDataTable(list);
    }

    /**
     * 导出医生管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:doctor:export')")
    @Log(title = "医生管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HomeDoctor homeDoctor)
    {
        List<HomeDoctor> list = homeDoctorService.selectHomeDoctorList(homeDoctor);
        ExcelUtil<HomeDoctor> util = new ExcelUtil<HomeDoctor>(HomeDoctor.class);
        util.exportExcel(response, list, "医生管理数据");
    }

    /**
     * 获取医生管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:doctor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(homeDoctorService.selectHomeDoctorById(id));
    }

    /**
     * 新增医生管理
     */
    @PreAuthorize("@ss.hasPermi('system:doctor:add')")
    @Log(title = "医生管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HomeDoctor homeDoctor)
    {
        homeDoctor.setCreateTime(new Date());
        homeDoctor.setSign(0L);
        homeDoctor.setRating(BigDecimal.valueOf(0.0));
        return toAjax(homeDoctorService.insertHomeDoctor(homeDoctor));
    }

    /**
     * 修改医生管理
     */
    @PreAuthorize("@ss.hasPermi('system:doctor:edit')")
    @Log(title = "医生管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HomeDoctor homeDoctor)
    {
        return toAjax(homeDoctorService.updateHomeDoctor(homeDoctor));
    }

    /**
     * 删除医生管理
     */
    @PreAuthorize("@ss.hasPermi('system:doctor:remove')")
    @Log(title = "医生管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(homeDoctorService.deleteHomeDoctorByIds(ids));
    }
    /*通过sysUserId查询医生信息*/
    @GetMapping("/sysUserId/{sysUserId}")
    @PreAuthorize("@ss.hasPermi('system:doctor:remove')")
    public HomeDoctor  selectHomeDoctorBySysUserId(@PathVariable Long sysUserId){
        System.out.println("sysUserId"+""+sysUserId);
        return homeDoctorService.selectHomeDoctorBySysUserId(sysUserId);
    }
    /*通过医生的id查询医生的标签*/
    @GetMapping("/tag/{id}")
    @PreAuthorize("@ss.hasPermi('system:doctor:remove')")
    public List<HomeTag> selectHomeTagByDoctorId(@PathVariable Long id){
        System.out.println("id"+""+id);
        return homeDoctorService.selectHomeTagByDoctorId(id);
    }
}
